"""
  以测试环境的323为列
"""
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC



def login(driver, recode):
    # 第一步，打开登录url
    recode.update(
        {"case1": "login"}
    )
    try:
        driver.get("http://135.0.123.121:8088/tenement/#/login")
    except Exception as e:
        #  如果打开url报错 记录报错信息
        recode.update({
            "step1": {
                "name": "打开url：http://135.0.123.121:8088/tenement/#/login",
                "msg": f"{e}"
            }

        })
    else:
        # 如果没有报错
        recode.update({
            "step1": {
                "name": "打开url：http://135.0.123.121:8088/tenement/#/login",
                "msg": "操作成功"
            }
        })
    # 第二部， 输入用户名
    try:
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='app']/div/div/div/div/form/div[1]/div/div/div/input").send_keys("superManager")
    except Exception as e:
        recode.update({
            "step2": {
                "name": "输入用户名",
                "msg": f"{e}"
            }
        })
    else:
        recode.update({
            "step2": {
                "name": "输入用户名",
                "msg": "操作成功"
            }
        })
    # 第三步， 输入密码
    try:
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='app']/div/div/div/div/form/div[3]/div/div/div/input").send_keys(
            "dL!H&?8j3DAX")
    except Exception as e:
        recode.update({
            "step3": {
                "name": "输入密码",
                "msg": f"{e}"
            }
        })
    else:
        recode.update({
            "step3": {
                "name": "输入密码",
                "msg": "操作成功"
            }
        })
    # 第四步， 点击登录
    try:
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='app']/div/div/div/div/form/div[5]/div/button").click()
    except Exception as e:
        recode.update({
            "step4": {
                "name": "点击登录",
                "msg": f"{e}"
            }
        })
    else:
        recode.update({
            "step4": {
                "name": "点击登录",
                "msg": "操作成功"
            }
        })
    # 扫描是否有报错提示
    try:
        message = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.CLASS_NAME, "el-message__content"))
        ).text
    except Exception as e:
        recode.update({
            "step5": {
                "name": "扫描提示信息",
                "msg": f"{e}"
            }
        })
    else:
        recode.update({
            "step5": {
                "name": "扫描提示信息",
                "msg": message
            }
        })





# if __name__ == '__main__':
#     from utils.send_msg_to_dingtalk import TestCaseReporter
#     driver = webdriver.Edge()
#     recode = dict()
#     login(driver, recode)
#     # 配置发送地址和安全标签
#     WEBHOOK = ("https://oapi.dingtalk.com/robot/send?access_token"
#                "=d2d92873b36e69e9d89132b5e920acdfe1b4c4dd857e92e7b9f55a1822811479")
#     SECRET = "SECa998bdb33cc58b4a509ba67ee5741ce6dfba69bc3fc89f80916338a041d0d591"
#
#     # 创建报告器并发送报告
#     reporter = TestCaseReporter(WEBHOOK, SECRET)
#     reporter.send_test_report(recode, at_all=True)
